﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

using System.Windows.Threading;

using System.Diagnostics;

using SlotRacer.Library;

namespace SlotRacer.Demo
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        Library.Track myTrack = new Library.Track();

        SlotRacer.Library.Controller.Simulation myController = new SlotRacer.Library.Controller.Simulation();

        Handle testData = new Handle();

        DispatcherTimer dispatcherTimer = new DispatcherTimer();

        public MainWindow()
        {
            InitializeComponent();

            dispatcherTimer.Tick += dispatcherTimer_Tick;
            dispatcherTimer.Interval = new TimeSpan(10000000);
            dispatcherTimer.Start();

            StatusText.Text = myController.Name + "\n";
            StatusText.Text = StatusText.Text + myController.Id + "\n";
            StatusText.Text = StatusText.Text + "v" + myController.Version + "\n";

            updateHandles();

            myController.Connect();
            myController.HandleChange += myController_HandleChange;
        }

        void dispatcherTimer_Tick(object sender, EventArgs e)
        {
            updateHandles();
        }

        void updateHandles()
        {
            Handle1.Minimum = 0;
            Handle1.Maximum = 1000;
            Handle1.Value = testData.Throttle;

            Handle2.Minimum = 0;
            Handle2.Maximum = 1000;
            Handle2.Value = 512;

            Handle3.Minimum = 0;
            Handle3.Maximum = 1000;
            Handle3.Value = 280;

            Handle4.Minimum = 0;
            Handle4.Maximum = 1000;
            Handle4.Value = 900;

            Handle5.Minimum = 0;
            Handle5.Maximum = 1000;
            Handle5.Value = 485;

            Handle6.Minimum = 0;
            Handle6.Maximum = 1000;
            Handle6.Value = 1000;
        }

        void myController_HandleChange(object sender, HandleEventArgs e)
        {
            Library.Controller.Base tempController = (Library.Controller.Base)sender;
            testData = e.Handle;
        }
    }
}
